<?php
require_once 'phpmoko/lib/common.php';

require_once 'phpmoko/ui/Form/FormBase.php';
require_once 'phpmoko/ui/Label.php';

class RadioButton extends FormBase
{
	private $enabled = true;
	private $label;
	private $value = null;
	private $checked = false;

	function __construct($name, $label)
	{
		parent::__construct();

		$this->name = $name;

		$this->label = new Label($label);
		$this->label->setLinkedWidget($this);
	}

	function setEnabled($enabled)
	{
		$this->enabled = $enabled;
	}

	function setValue($value)
	{
		$this->value = $value;
	}

	function setChecked($value)
	{
		$this->checked = $value;
	}

	function toString()
	{
		$str = '<span class="pmk-RadioButton';

		if (!$this->enabled)
			$str .= ' pmk-RadioButton-disabled';

		$str .= '">';

		$str .= '<input';

		$str .= ' type="radio"';

		if (!$this->enabled)
			$str .= ' disabled="disabled"';

		if ($this->name != null)
			$str .= ' name="' . $this->name . '"';

		$str .= ' id="' . $this->id . '"';

		if ($this->checked)
			$str .= ' checked="checked"';

		if ($this->value != null)
			$str .= ' value="' . $this->value . '"';

		$str .= '>';

		$str .= $this->label->toString();

		$str .= '</span>';

		return $str;
	}
}
?>